
/* Allows us to change the addresses
 * of symbols withen the GEX file
 */

void relocate(void* program, unsigned int align)
{
	char* GEX = (char*)program;
	GEXHdr* hdr = (GEXHdr*)GEX;
	if(strncmp("GEX4 SC",hdr->magic,7) == 0)
	{
		for(int i = 0; i < hdr->sectionCount;i++)
		{
			GEXShdr* section = (GEXShdr*)(GEX + (hdr->sectionTable + (i * sizeof(GEXShdr))));
			if(strncmp(section->name,".reloc",5) == 0)
			{
				char* ptr = (char*)(GEX + section->ptr);
				for(unsigned int p = 0; p < section->length;p += 9)
				{
					unsigned int address = *(unsigned int*)&ptr[p];
					unsigned int symbol = *(unsigned int*)&ptr[p + 4];
					char type = ptr[p + 8];
					unsigned int* ram = (unsigned int*)(RAM + align + address);
					
					ram[0] = ram[0] + align;
					//printf("reloc%s\n", getSymName(GEX,getSymAddress(GEX,symbol)));
				}
			}
		}
	}

		
}
